#!/usr/bin/python3

'''
This is the build tool for the coffee scripts of the tree framework.

To edit settings, look into config.py
'''

import os
import config

all_files = {}

for root, dirs, files in os.walk('.'):
    root = os.path.abspath(root)
    for file in files:
        if not file.endswith('.coffee'):
            continue
        try:
            level = config.levels[file]
        except KeyError:
            level = config.STANDARD_LEVEL
        all_files[os.path.join(root, file)] = level
        
f = open(config.output, 'w')

files = []

for x in range(1, max(list(all_files.values())) + 1):
    for key, value in all_files.items():
        if value == x:
            files.append(key)
            
f.write('''#This file was generated by the lignum build tool. Do not mofify this file directly.


''')
            
for file in files:
    f.write(open(file, 'r').read())
    
f.close()

os.system('coffee -c ' + os.path.abspath(config.output))
